package com.twu.biblioteca.model;

public abstract class LibraryItem {

    protected final static String LIST_SEPARATOR = "  |  ";
    private static final String INVALID_YEAR_MESSAGE = "Year Entered was not in the Correct Format e.g 2014";
    private final String title;
    private final String yearPublished;
    private boolean checkedOut;

    public LibraryItem(String title, String yearPublished) {
        this.title = title;
        this.checkedOut = false;
        this.yearPublished = (getValidPublishYear(yearPublished));
    }

    private String getValidPublishYear(String yearPublished) {
        if (yearPublished.matches("[0-9]{4}?")) // Year in format XXXX
            return yearPublished;
        else
            throw new IllegalArgumentException(INVALID_YEAR_MESSAGE);
    }

    public String getTitle() {
        return title;
    }

    public String getYearPublished() {
        return yearPublished;
    }

    public boolean isCheckedOut() {
        return checkedOut;
    }

    public void setCheckedOut(boolean checkedOut) {
        this.checkedOut = checkedOut;
    }

    public abstract boolean hasDetails(String... args);
}
